import { _decorator, AudioClip, Prefab, SpriteAtlas, SpriteFrame } from 'cc'
import { ZAssetManager, ZController } from './Zcc'
import { SettingManager } from './data/SettingManager'
import { RoundController } from './game/Controllers/RoundController'
import { MenuController } from './ui/Controllers/MenuController'
const { ccclass } = _decorator

@ccclass('main')
export class main extends ZController {
	private roundController: RoundController = null
	private menuController: MenuController = null

	protected onControllerLoad(): void {
		console.log('main onControllerLoad')

		this.loadGame()
	}
	private async loadGame() {
		// 加载设置
		await SettingManager.instance.initialize()
		// 加载资源
		await ZAssetManager.instance.preload(
			[
				{ path: SettingManager.instance.settings.skin_dice, type: SpriteAtlas },
				{ path: SettingManager.instance.settings.skin_shaker, type: SpriteFrame },
				{ path: SettingManager.instance.settings.sound_shake, type: AudioClip },
				{ path: SettingManager.instance.settings.dice_prefab, type: Prefab }
			],
			(finished: number, total: number) => {
				console.log('loadGame', finished, total)
			}
		)

		// 加载Controller

		this.getPropertyBinder().bindBatch({
			roundController: { path: 'game/Round', component: RoundController },
			menuController: { path: 'ui', component: MenuController }
		})

		console.log('loadSettings', SettingManager.instance.settings)
		ZAssetManager.instance.printLoadedAssets()
	}
}
